package com.zcl.javaClassAndObject.exception;

/**
 * @Description:
 * @author: zcl
 * @date: 2021/12/14  11:01
 */
public class Rethrowing {
    public static void f() throws Exception{
        System.out.println("Originating the exception in f()");
        throw new Exception("throw from f()");
    }

    public static void g() throws Throwable{
        try {
            f();
        }catch (Exception e){
            System.out.println("Inside g(),e.printStackTrace");
            e.printStackTrace();
//            throw e;
             throw e.fillInStackTrace(); // 18
        }
    }

    public static void main(String[] args) throws Throwable {
        try {
            g();
        } catch (Exception e){
            System.out.println("Caught in main, e.printStackTrace");
            e.printStackTrace();
        }
    }
}
/**
 * Connected to the target VM, address: '127.0.0.1:59226', transport: 'socket'
 * Originating the exception in f()
 * Inside g(),e.printStackTrace
 * java.lang.Exception: throw from f()
 * 	at com.zcl.javaClassAndObject.exception.Rethrowing.f(Rethrowing.java:11)
 * 	at com.zcl.javaClassAndObject.exception.Rethrowing.g(Rethrowing.java:16)
 * 	at com.zcl.javaClassAndObject.exception.Rethrowing.main(Rethrowing.java:27)
 * Caught in main, e.printStackTrace
 * java.lang.Exception: throw from f()
 * 	at com.zcl.javaClassAndObject.exception.Rethrowing.f(Rethrowing.java:11)
 * 	at com.zcl.javaClassAndObject.exception.Rethrowing.g(Rethrowing.java:16)
 * 	at com.zcl.javaClassAndObject.exception.Rethrowing.main(Rethrowing.java:27)
 * */